<?php
// +----------------------------------------------------------------------
// | quanli team
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2020 http://www.fistforward.com/ All rights reserved.
// +----------------------------------------------------------------------
// | create by allen.qiang
// +----------------------------------------------------------------------


/**
 * 投票操作功能
 * @package  htdocs
 * @subpackage  quanliadmin
 * create by allen.qiang
 */

require 'module/base/contentHandler.class.php';

class pa_vote {
	//入口
	public function execute(){
		global $G_PGLOB;
		$operFlg = isset($_REQUEST['operFlg']) ? $_REQUEST['operFlg'] : null;
		switch ($operFlg){
			case 1:
				$this->init();
				break;
			case 2:
			case 3:
				$this->edit();
				break;
			case 4:
				$this->showResult();
				break;
			default:
				$G_PGLOB->smarty->assign('error_msg','参数错误');
				$G_PGLOB->smarty->display('comm/errorDisplay.tpl');
				break;
		}
	}
	
	//列表页初始化
	private function init() {
		global $G_PGLOB;
		$G_PGLOB->smarty->display('content/vote.tpl');
	}
	
	private function edit() {
		global $G_PGLOB;
		
		//operFlg=2 新增； operFlg=3 编辑
		$operFlg = isset($_REQUEST['operFlg']) ? $_REQUEST['operFlg'] : null;
		//投票uuid
		$vote_uuid = (isset($_REQUEST['vote_uuid']) && is_string($_REQUEST['vote_uuid'])) ? $_REQUEST['vote_uuid'] : '';
		
		if ($operFlg == 2){
		
			//显示新增
			$G_PGLOB->smarty->assign('operFlg', 1);
		
		}elseif ($operFlg == 3){
		
			//显示编辑
			$G_PGLOB->smarty->assign('operFlg', 2);
			//实例化内容类
			$contentHandler = new contentHandler($G_PGLOB->DBCA);
			//根据传入的vote_uuid得到对应的投票信息
			$result_vote = $contentHandler->searchAllVoteInfo(array('vote_uuid'=>$vote_uuid,'sortname'=>'option_sortBy','sortorder'=>'ASC'));
			
			if ($result_vote['code'] != 200 || empty($result_vote['message']['data'])){
				$G_PGLOB->smarty->assign('error_msg','未找到对应投票或该投票已被删除');
				$G_PGLOB->smarty->display('comm/errorDisplay.tpl');
			}else {
				$G_PGLOB->smarty->assign('voteInfo', $result_vote['message']['data']);
			}
		}
		
		$G_PGLOB->smarty->display('content/voteEdit.tpl');
	}
	
	private function showResult(){
		global $G_PGLOB;
		
		$operFlg = isset($_REQUEST['operFlg']) ? $_REQUEST['operFlg'] : null;
		
		$vote_uuid = (isset($_REQUEST['vote_uuid']) && is_string($_REQUEST['vote_uuid'])) ? $_REQUEST['vote_uuid'] : '';
		
		$vote_name = (isset($_REQUEST['vote_name']) && is_string($_REQUEST['vote_name'])) ? $_REQUEST['vote_name'] : '';
		
		if (empty($operFlg) || empty($vote_uuid) || empty($vote_name)){
			$G_PGLOB->smarty->assign('error_msg','传值错误或该投票已被删除');
			$G_PGLOB->smarty->display('comm/errorDisplay.tpl');
		}else {
			$G_PGLOB->smarty->assign('vote_uuid',$vote_uuid);
			$G_PGLOB->smarty->assign('vote_name',$vote_name);
			$G_PGLOB->smarty->display('content/voteResult.tpl');
		}
	}
}